//
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/16.
//

import Foundation
import LeanCloud

//制作完成音色
class MakeVoiceDoneViewModel : BaseViewModel {
    @Published var items = [AiVoiceCrowdBean]()
    @Published var status = ""

    func getData(_ isRefresh: Bool = false, status : Int) {
        requestList(isRefresh: isRefresh) {
            let query = LCQuery(className: "AiVoiceCrowd")
            query.whereKey("status", .equalTo(status))
            query.whereKey("hide", .notEqualTo(true))
            query.whereKey("count", .descending) //count 降序
            query.limit = self.pageSize
            query.skip = self.pageNo * self.pageSize
            let list = try await LeancloudManager.instance.getList(query: query, modeType: AiVoiceCrowdBean.self)
            try check(!isRefresh || !list.isEmpty, "暂无音色")
            return list
        } suc: {
            self.status = ""
            self.items.append(contentsOf: $0)
        } fail: {
            self.status = $0.message
        }
    }
    
}
